// 寻找sign算法位置
var addrNewStringUTF = null;

//1.寻找底层NewStringUTF的地址
var symbols = Module.enumerateSymbolsSync("libart.so");
for (var i = 0; i < symbols.length; i++) {
    var symbol = symbols[i];

    // JNI开发：env->NewStringUTF(env,"...")
    // asdfasdfasdfasd_NewStringUTF_CheckJNI_fasdfasfasdf
    if (symbol.name.indexOf("NewStringUTF") >= 0 && symbol.name.indexOf("CheckJNI") < 0) {
        addrNewStringUTF = symbol.address;
        console.log("NewStringUTF is at ", symbol.address, symbol.name);
    }
}


//2.基于frida对C中的函数进行Hook
//  env->NewStringUTF(env,"...")
if (addrNewStringUTF != null) {
    Interceptor.attach(addrNewStringUTF, {
        onEnter: function (args) {
            var c_string = args[1];     //取到的是指针的数据类型的数据
            var dataString = c_string.readCString();    // readCString读取指针数据类型数据，字符串

            if (dataString) {
                if (dataString.length === 32) {
                    console.log(dataString);
                    //读取当前是在那个so文件，那个地址
                    //console.log(Thread.backtrace(this.context, Backtracer.ACCURATE).map(DebugSymbol.fromAddress).join('\n') + '\n');
                    console.log(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Throwable").$new()));
                }
            }

        }
    });
}

// frida -UF  -l  18_hook_NewstringUTF.js -o v1.txt